﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <Style TargetType="{x:Type GroupBox}">
        <Setter Property="BorderBrush" Value="{DynamicResource Brush.GroupBox.Border}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Foreground" Value="{DynamicResource Brush.GroupBox.Foreground}" />
        <Setter Property="Padding" Value="10"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupBox}">
                    <ControlTemplate.Resources>
                        <BorderGapMaskConverter x:Key="BorderGapMaskConverter"/>
                    </ControlTemplate.Resources>
                    <Grid SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="6" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="6" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="6" />
                        </Grid.RowDefinitions>
                        
                        <Border 
                            Grid.Column="0" 
                            Grid.ColumnSpan="4" 
                            Grid.Row="1" 
                            Grid.RowSpan="3" 
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="Transparent" 
                            Background="{TemplateBinding Background}"
                            CornerRadius="4"/>
                        <Border 
                            Grid.Column="1"
                            Grid.Row="0" 
                            Grid.RowSpan="2"
                            Name="Header" 
                            Padding="5,1,5,0">
                            <ContentPresenter 
                                ContentSource="Header" 
                                TextElement.FontFamily="{TemplateBinding FontFamily}"
                                TextElement.FontSize="{TemplateBinding FontSize}"
                                TextElement.FontStretch="{TemplateBinding FontStretch}"
                                TextElement.FontStyle="{TemplateBinding FontStyle}"
                                TextElement.FontWeight="{TemplateBinding FontWeight}"
                                TextElement.Foreground="{TemplateBinding Foreground}"
                                RecognizesAccessKey="true" 
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Border>
                        <ContentPresenter 
                            Grid.Column="1" 
                            Grid.ColumnSpan="2" 
                            Grid.Row="2" 
                            Margin="{TemplateBinding Padding}" 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        <Border 
                            Grid.ColumnSpan="4"  
                            Grid.Row="1" 
                            Grid.RowSpan="3" 
                            CornerRadius="3"
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Padding="5">
                            <Border.OpacityMask>
                                <MultiBinding Converter="{StaticResource BorderGapMaskConverter}" ConverterParameter="7">
                                    <Binding ElementName="Header" Path="ActualWidth" />
                                    <Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
                                    <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
                                </MultiBinding>
                            </Border.OpacityMask>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>